package com.hanson.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hanson.mapper.TbIpListLogMapper;
import com.hanson.pojo.vo.TbIpListLog;
import com.hanson.service.ITbIpListLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * ip名单更新记录日志 服务实现类
 * </p>
 *
 * @author HansonLee
 * @since 2022-08-31
 */

@Slf4j
@Service
public class TbIpListLogServiceImpl extends ServiceImpl<TbIpListLogMapper, TbIpListLog> implements ITbIpListLogService {

        @Resource
        private TbIpListLogMapper tbIpListLogMapper;

        /**
        *
        * 分页查询tbIpListLog
        *
        * @param condition    数据筛选条件
        * @param page      分页对象
        * @return {@link Page< TbIpListLog>}      传进来的分页对象，封装了查询数据结果集
        * @author HansonLee
        * @date 2022-08-31
        **/
        @Override
        public Page<TbIpListLog> list(String condition, Page<TbIpListLog> page) {
        QueryWrapper<TbIpListLog> wrapper = new QueryWrapper<TbIpListLog>();
        TbIpListLog tbIpListLog = new TbIpListLog();
        //↓↓↓↓↓↓↓↓为TbIpListLog查询对象设置条件set condition↓↓↓↓↓↓↓↓

        //↑↑↑↑↑↑↑↑为TbIpListLog查询对象设置条件set condition↑↑↑↑↑↑↑↑
        wrapper.setEntity(tbIpListLog);
        return super.page(page,wrapper);
        }

        /**
        *
        * 添加新tbIpListLog
        *
        * @param tbIpListLog      需要添加的tbIpListLog
        * @return {@link int}
        * @author HansonLee
        * @date 2022-08-31
        **/
        @Override
        public int add(TbIpListLog tbIpListLog) {
        return baseMapper.insert(tbIpListLog);
        }

        /**
        *
        * 根据条件更新tbIpListLog
        *
        * @param condition     新数据以及更新条件，使用tbIpListLog实体类封装
        * @return {@link int}
        * @author HansonLee
        * @date 2022-08-31
        **/
        @Override
        public int update(TbIpListLog condition) {
        //条件封装类
        UpdateWrapper<TbIpListLog> wrapper = new UpdateWrapper<TbIpListLog>();
//        wrapper.setEntity(condition);
        //封装更新条件，wrapper.eq(String column,Object value),column表示数据库字段，value是字段对应的值
                wrapper.set("ip",condition.getIp()).eq("id",condition.getId());
        return baseMapper.update(null,wrapper);
        }

        /**
        *
        * 根据条件删除tbIpListLog
        *
        * @param condition     删除条件，使用tbIpListLog实体类封装
        * @return {@link int}
        * @author HansonLee
        * @date 2022-08-31
        **/
        @Override
        public int delete(TbIpListLog condition) {
        //条件封装类
        UpdateWrapper<TbIpListLog> wrapper = new UpdateWrapper<TbIpListLog>();
        wrapper.setEntity(condition);
        //封装删除条件，wrapper.eq(String column,Object value),column表示数据库字段，value是字段对应的值

        return baseMapper.delete(wrapper);
        }

        /**
        *
        * 根据id删除tbIpListLog
        *
        * @param id     删除条件，需要删除的id
        * @return {@link int}
        * @author HansonLee
        * @date 2022-08-31
        **/
        @Override
        public int deleteById(Serializable id) {
        return baseMapper.deleteById(id);
        }

        /**
         *
         * 根据条件查询一条tbIpListLog
         *
         * @param condition     查询条件
         * @return {@link TbIpListLog}
         * @author HansonLee
         * @date 2022-08-31
         **/
        @Override
        public TbIpListLog selectOne(TbIpListLog condition){
        QueryWrapper<TbIpListLog> wrapper = new QueryWrapper<>();
        wrapper.setEntity(condition);
        //封装查询条件，wrapper.eq(String column,Object value),column表示数据库字段，value是字段对应的值

        return baseMapper.selectOne(wrapper);
        }

        /**
         *
         * 根据id查询tbIpListLog
         *
         * @param id     id
         * @return {@link TbIpListLog}
         * @author HansonLee
         * @date 2022-08-31
         **/
        @Override
        public TbIpListLog selectById(Serializable id){
        return baseMapper.selectById(id);
        }

        /**
         *
         * 根据条件查询tbIpListLog
         *
         * @param condition     查询条件
         * @return {@link List<TbIpListLog>}
         * @author HansonLee
         * @date 2022-08-31
         **/
        @Override
        public List<TbIpListLog> selectList(TbIpListLog condition){
        QueryWrapper<TbIpListLog> wrapper = new QueryWrapper<>();
        wrapper.setEntity(condition);
        //封装查询条件，wrapper.eq(String column,Object value),column表示数据库字段，value是字段对应的值

        return baseMapper.selectList(wrapper);
        }

        /**
         *
         * 根据条件统计tbIpListLog
         *
         * @param condition     统计条件
         * @return {@link Integer}
         * @author HansonLee
         * @date 2022-08-31
         **/
        @Override
        public Integer selectCount(TbIpListLog condition){
        QueryWrapper<TbIpListLog> wrapper = new QueryWrapper<>();
        wrapper.setEntity(condition);
        //封装查询条件，wrapper.eq(String column,Object value),column表示数据库字段，value是字段对应的值

        return baseMapper.selectCount(wrapper);
        }
}
